package words

import (
	"context"
	"star/api/words/v1"
	"star/internal/logic/users"
	"star/internal/logic/words"
	"star/internal/model"
)

func (c *ControllerV1) RandList(ctx context.Context, req *v1.RandListReq) (res *v1.RandListRes, err error) {
	uid, err := users.GetUid(ctx)
	if err != nil {
		return nil, err
	}
	wordlist, err := words.GetRandWords(ctx, uid, req.Limit)
	var list []model.WordList

	for _, v := range wordlist {
		list = append(list, model.WordList{
			Id:                 v.Id,
			Word:               v.Word,
			Definition:         v.Definition,
			ExampleSentence:    v.ExampleSentence,
			ChineseTranslation: v.ChineseTranslation,
			Pronunciation:      v.Pronunciation,
			ProficiencyLevel:   v.ProficiencyLevel,
			CreatedAt:          v.CreatedAt,
			UpdatedAt:          v.UpdatedAt,
		})
	}
	return &v1.RandListRes{
		List: list,
	}, err
}
